<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-left">
        <h2>欢迎回来</h2>
        <p>请登录您的账号以继续访问</p>
      </div>
      <form class="login-form" @submit.prevent="handleLogin">
        <h3 class="title">系统登录</h3>
        
        <div class="form-item">
          <label>用户名</label>
          <input
            v-model="loginForm.username"
            type="text"
            placeholder="请输入用户名"
            autocomplete="off"
            required
          >
        </div>
        
        <div class="form-item">
          <label>密码</label>
          <input
            v-model="loginForm.password"
            type="password"
            placeholder="请输入密码"
            autocomplete="off"
            required
            @keyup.enter="handleLogin"
          >
        </div>
        
        <div class="form-item">
          <button 
            type="submit"
            :disabled="loading"
            class="login-button"
          >
            {{ loading ? '登录中...' : '登录' }}
          </button>
        </div>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import {login} from '@/api/login/index'
const router = useRouter()
const userStore = useUserStore()

const loginForm = reactive({
  username: '',
  password: ''
})

const loading = ref(false)

const handleLogin = async () => {
  if (!loginForm.username || !loginForm.password) {
    alert('请输入用户名和密码')
    return
  }

  try {
    loading.value = true
    await login(loginForm)
    router.push('/')
    alert('登录成功')
  } catch (error) {
    alert(error.message || '登录失败')
  } finally {
    loading.value = false
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
    overflow: hidden;
  .login-box {
    display: flex;
    width: 900px;
    min-height: 480px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    overflow: hidden;

    .login-left {
      flex: 1;
      padding: 40px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: white;

      h2 {
        font-size: 36px;
        margin-bottom: 10px;
        font-weight: 600;
      }

      p {
        font-size: 16px;
        opacity: 0.8;
      }
    }

    .login-form {
      flex: 1;
      padding: 40px;
      background: white;

      .title {
        text-align: center;
        margin: 0 0 30px;
        font-size: 28px;
        color: #333;
        font-weight: 600;
      }

      .form-item {
        margin-bottom: 25px;

        label {
          display: block;
          margin-bottom: 8px;
          font-size: 14px;
          color: #666;
          font-weight: 500;
        }

        input {
          width: 100%;
          height: 45px;
          padding: 0 15px;
          border: 2px solid #eee;
          border-radius: 8px;
          font-size: 15px;
          transition: all 0.3s ease;

          &:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
          }

          &::placeholder {
            color: #999;
          }
        }

        .login-button {
          width: 100%;
          height: 45px;
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
          border: none;
          border-radius: 8px;
          color: white;
          font-size: 16px;
          font-weight: 500;
          cursor: pointer;
          transition: all 0.3s ease;

          &:hover {
            transform: translateY(-1px);
            box-shadow: 0 7px 14px rgba(0, 0, 0, 0.1);
          }

          &:active {
            transform: translateY(1px);
          }

          &:disabled {
            background: #ccc;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
          }
        }
      }
    }
  }
}

// 响应式设计
@media screen and (max-width: 768px) {
  .login-container {
    padding: 15px;

    .login-box {
      width: 100%;
      flex-direction: column;

      .login-left {
        padding: 30px;
        text-align: center;

        h2 {
          font-size: 28px;
        }
      }

      .login-form {
        padding: 30px;
      }
    }
  }
}
</style>